package com.yoshino.state;

import lombok.Data;

/**
 * @author yoshino
 **/
@Data
public class RaffleActivity {

    // 当前状态
    State state = null;
    // 奖品数量
    int count = 0;

    State noRaffleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleState(this);
    State dispenseRaffleState = new DispenseRaffleState(this);
    State dispenseOutState = new DispenseOutState(this);

    //构造器
    //1,初始化当前的状态为noRaff1 leState(即不能抽奖的状态)
    //2。初始化奖品的数量
    public RaffleActivity(int count) {
        this.state = getNoRaffleState();
        this.count = count;
    }

    /**
     * 扣除积分
     */
    public void deduceMoney() {
        state.deduceMoney();
    }

    /**
     * 是否抽中奖品
     */
    public void raffle() {
        //如果当前的状态是抽奖成功
        if (state.raffle()) {
            state.dispensePrize();
        }
    }

    /**
     * 发放奖品
     */
    public void dispensePrize() {
        state.dispensePrize();
    }

    public int getCount() {
        int curCount = count;
        count--;
        return curCount;
    }
}
